﻿<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class search extends CI_Controller {

	public function __construct(){
		parent::__construct();
	}
	
	public function index($lang)
	{
		//$this->output->cache(1);//caching trong 5 phut
		$data['wordSearch'] = trim($this->input->post('w', TRUE));
		$data['lang'] = $lang;
		if($data['wordSearch']!=""){
			header('Location:'.Base_url_TuDien.'/devi/'.$data['wordSearch']);
			return ;
		}
		$this->load->Model("m_search");
		$data['Words'] = $this->m_search->get100($lang);// tra ve du lieu trong bang
		$this->load->view("trangchu",$data);
	}
	
	public function searchWord($wordSearch,$lang){
		//$this->output->cache(10);//caching trong 5 phut
		
		//paging
		$this->load->library('pagination');
		$config['base_url'] = Base_url_TuDien.'/'.$lang.'/'.$wordSearch.'?pr=true';
		$config['per_page'] = 2; 
		$config['page_query_string'] = TRUE;
		$config['query_string_segment'] = 'p';
		
		$this->load->Model("m_search");
		$data['wordSearch']= $wordSearch;
		$data["Words"]=$this->m_search->search($wordSearch,$lang);
		$data["total_result"] = count($data["Words"]);
		$data['lang'] = $lang;
		$this->load->view("v_search",$data);
		
		$config['total_rows'] = count($data["Words"]);
		$this->pagination->initialize($config); 
		/*
		echo $config['total_rows'];
		echo "<br />";
		echo $this->pagination->create_links();
		*/
	}
	
	///view/devi/b.html	
	public function getFirtChart($wordSearch,$lang){
		$this->output->cache(10);//caching trong 5 phut
		$this->load->Model("m_search");
		$data['wordSearch']= $wordSearch;
		$data["Words"]=$this->m_search->getFirtChart($wordSearch,$lang);
		$data["total_result"] = count($data["Words"]);
		$data['lang'] = $lang;
		$this->load->view("v_search",$data);
	}
}